package com.itheima.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.common.PageResult;
import com.itheima.domain.SmsHomeNewProduct;
import com.itheima.mapper.SmsHomeNewProductMapper;
import com.itheima.service.SmsHomeNewProductService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 新鲜好物表 服务实现类
 * </p>
 *
 * @author zhuguo
 * @since 2022-11-10
 */
@DubboService
public class SmsHomeNewProductServiceImpl extends ServiceImpl<SmsHomeNewProductMapper, SmsHomeNewProduct> implements SmsHomeNewProductService {

    @Autowired
    SmsHomeNewProductMapper smsHomeNewProductMapper;

    @Override
    public PageResult pageList(Integer pageNum, Integer pageSize, String productName, Integer recommendStatus) {
        Page<SmsHomeNewProduct> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsHomeNewProduct> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(productName),SmsHomeNewProduct::getProductName,productName);
        queryWrapper.eq(recommendStatus!=null,SmsHomeNewProduct::getRecommendStatus,recommendStatus);
        smsHomeNewProductMapper.selectPage(page,queryWrapper);
        return new PageResult(pageNum,pageSize,page.getTotal(),page.getPages(),page.getRecords());

    }
}
